<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--   获取绝对路径 -->
<c:set var="ctx" value="${pageContext.request.contextPath }" />
<c:set var="u" value="${requestScope.user }" />
<%@ include file="/common/include/include.jsp"%>
</head>
<body>

	<div id="content-container">
		<%@ include file="/common/include/pageTitleBread.jsp"%>
		<div id="page-content">
			<div class="col-lg-12">
				<div class="panel">
					<div class="panel-heading">
						<h3 class="panel-title">${requestScope.nowBread }</h3>
					</div>
					<form id="editForm" class="panel-body form-horizontal form-padding">
					
						<input type="hidden" id = "opreate" name="opreate" value="${requestScope.nowBread }">
					
						<div class="form-group">
							<label class="col-md-3 control-label" for="demo-text-input">所属单位</label>
							<div class="col-md-5">
								<div class="input-group mar-btm">
									<input type="text" id="orgname" name="departmentname"
										class="form-control" disabled
										value="${u!=null?u.departmentname:'' }"> <input
										type="hidden" id="orgid" name="departmentid"
										class="form-control" value="${u!=null?u.departmentid:'' }">
									<input type="hidden" name="id" class="form-control"
										value="${u!=null?u.id:'' }"> <span
										class="input-group-btn">
										<button class="btn btn-mint" type="button"
											onclick="selectOneOrg()">选择</button>
									</span>
								</div>
								<small class="help-block">请选择所属单位</small>
							</div>
						</div>
						<div class="form-group">
							<label class="col-md-3 control-label" for="demo-text-input">用户名</label>
							<div class="col-md-9">
								<input type="text" name="username" class="form-control"
									value="${u!=null?u.username:'' }"> <small
									class="help-block">请输入用户名(用来登录系统)</small>
							</div>
						</div>
						<div class="form-group">
							<label class="col-md-3 control-label" for="demo-text-input">密码</label>
							<div class="col-md-9">
								<input type="password" name="password" class="form-control" value=""
									<c:if test="${u!=null }"> placeholder="如果您不想修改密码,请将此项留空!" </c:if> />
								<small class="help-block">请输入密码</small>
							</div>
						</div>
						<div class="form-group">
							<label class="col-md-3 control-label" for="demo-text-input">密码确认</label>
							<div class="col-md-9">
								<input type="password" name="password2" class="form-control" value=""
									<c:if test="${u!=null }"> placeholder="如果您不想修改密码,请将此项留空!" </c:if> />
								<small class="help-block">请再次输入密码</small>
							</div>
						</div>
						<div class="form-group">
							<label class="col-md-3 control-label" for="demo-text-input">用户姓名</label>
							<div class="col-md-9">
								<input type="text" name="name" class="form-control"
									value="${u!=null?u.name:'' }"> <small
									class="help-block">请输入用户姓名</small>
							</div>
						</div>
						<div class="form-group">
							<label class="col-md-3 control-label" for="demo-text-input">性别</label>
							<div class="col-md-9">
								<input id="sysUserSexMan" class="magic-radio" type="radio"
									name="sex" value="1"
									<c:if test="${u!=null&&u.sex=='1' }"> checked </c:if> />
								<label for="sysUserSexMan">男</label> <input id="sysUserSexWoman"
									class="magic-radio" type="radio" name="sex" value="0"
									<c:if test="${u!=null&&u.sex=='0' }"> checked </c:if> />
								<label for="sysUserSexWoman">女</label>
							</div>
						</div>
						<div class="form-group">
							<label class="col-md-3 control-label" for="demo-text-input">移动电话</label>
							<div class="col-md-9">
								<input type="text" name="mobile" class="form-control"
									value="${u!=null?u.mobile:'' }"> <small
									class="help-block">请输入移动电话</small>
							</div>
						</div>
						<div class="form-group">
							<label class="col-md-3 control-label" for="demo-text-input">邮箱地址</label>
							<div class="col-md-9">
								<input type="text" name="email" class="form-control"
									value="${u!=null?u.email:'' }"> <small
									class="help-block">请输入邮箱地址</small>
							</div>
						</div>
						<div class="form-group">
							<label class="col-md-3 control-label" for="demo-text-input">身份证号</label>
							<div class="col-md-9">
								<input type="text" name="idcard" class="form-control"
									value="${u!=null?u.idcard:'' }"> <small
									class="help-block">请输入身份证号</small>
							</div>
						</div>
						<div class="form-group">
							<label class="col-md-3 control-label" for="demo-text-input">是否是管理员</label>
							<div class="col-md-9">
								<input id="sysUserIsAdmin" class="magic-radio" type="radio"
									value="0" name="isAdmin"
									<c:if test="${u!=null&&u.isAdmin=='0' }"> checked </c:if> />
								<label for="sysUserIsAdmin">否</label> <input
									id="sysUserIsNotAdmin" class="magic-radio" type="radio"
									value="1" name="isAdmin"
									<c:if test="${u!=null&&u.isAdmin=='1' }"> checked </c:if> />
								<label for="sysUserIsNotAdmin">是</label>
							</div>
						</div>
						<div class="panel-footer">
							<div class="row">
								<div class="col-sm-9 col-sm-offset-3">
									<button class="btn btn-warning" type="reset">重置</button>
									<button class="btn btn-mint" type="submit">保存</button>
								</div>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>




		<script>
			var validPassword = {};//密码1
			var validPassword2 = {};//密码2
			var validUsername = {};//用户名 唯一性校验

			validPassword = {
				stringLength : {
					max : 15,
					message : '*密码长度必须小于15'
				}
			};
			validPassword2 = {
				stringLength : {
					max : 15,
					message : '*确认密码长度必须小于15'
				},
				identical : {
					field : 'password',
					message : '*两次输入密码不一致'
				}
			};
			validUsername = {
				notEmpty : {
					message : '*用户名不能为空'
				},
				stringLength : {
					max : 15,
					message : '*用户名长度必须小于15'
				}
			}

			function selectOneOrg() {
				//调用选择一个单位组件
				pointLion.selectOneOrg(function(orgNode) {
					var thisId = $("#orgId").val();//主键
					if (thisId == orgNode.id) {
						layer.closeAll();
						pointLion.alertMsg("您不能选择自己为父级节点!", "warning", "small",
								null);
						return;
					}
					$("#orgname").val(orgNode.name);//所选单位名称
					$("#orgid").val(orgNode.id);//所选单位id

				});
			}

			function save() {
				var data = common_ajax.ajaxFunc("/admin/user/saveOrUpdate", $(
						'#editForm').serialize(), "json", null);
				if (data.success) {
					pointLion.alertMsg("保存成功!", "success", "small", function() {
						doPjax(ctx + '/admin/user/getListPage');//跳转到列表页
					});
				}
			}
			

			$(document)
					.ready(
							function() {
								$('#editForm')
										.bootstrapValidator(
												{
													excluded : [ ":hidden" ],//关键配置，表示只对于隐藏域不进行验证，其他的表单元素都要验证
													fields : {
														"departmentname" : {
															validators : {
																notEmpty : {
																	message : '*所属单位不能为空'
																}
															}
														},
														"username" : {
															validators : validUsername
														},
														"password" : {
															validators : validPassword
														},
														"password2" : {
															validators : validPassword2
														},
														"name" : {
															validators : {
																notEmpty : {
																	message : '*用户姓名不能为空'
																},
																stringLength : {
																	max : 15,
																	message : '*确认密码长度必须小于15'
																}
															}
														},
														"mobile" : {
															validators : {
																regexp : {
																	regexp : /^1(3|4|5|7|8)\d{9}$/,
																	message : '*移动电话格式不对'
																}
															}
														},
														"email" : {
															validators : {
																regexp : {
																	regexp : /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/,
																	message : '*邮箱格式不对'
																},
																stringLength : {
																	max : 100,
																	message : '*您的邮箱地址也太长了吧'
																}
															}
														},
														"idcard" : {
															validators : {
																regexp : {
																	regexp : /^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/,
																	message : '*身份证号格式不对'
																}
															}
														}
													}
												}).on("success.form.bv",
												function(e) {
													save();
													return false;//阻止表单跳转
												});
							});
		</script>
	</div>
</body>
</html>